package com.pactera.madp.cp.controller.oms.taskpub;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.cp.api.dto.taskpub.TaskPageDTO;
import com.pactera.madp.cp.api.vo.task.TaskPageVO;
import com.pactera.madp.cp.service.TaskPubService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 任务发布审核
 */
@RestController
@RequestMapping("/taskpub-approval")
@Api(value = "taskpub-approval", tags = "任务发布审核")
@AllArgsConstructor
public class TaskPubApprovalController {

    @Resource
    private TaskPubService taskPubService;

    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public R<Page<TaskPageVO>> page(TaskPageDTO dto, Page page) {
        return R.ok(taskPubService.getApprovalPageByOut(dto,page));
    }

    @PutMapping("/approval")
    @ApiOperation("审批-发布任务")
    public R approval(@RequestParam("id") Integer id, String  opinion, Integer state) {
        if (state != 1 && state != 2) {
            return R.failed("审批状态不在可操作范围[1-拒绝、2-同意]内");
        }
        return taskPubService.approvalTaskById(id, opinion, state) ? R.ok() : R.failed();
    }

}
